<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>promise</title>
</head>
<body>
<script>
    //var arr=[1,2,3,4,5,6];
    //let [n1,n2,n3,n4,n5,n6]=arr;
    //let n=0;
    //function add() {
    //    n=n1+n2+n3+n4+n5+n6;
    //}
    function add(resolve, reject) {
        let arr = [1, 2, 3, 4, 5, 6];
        let n = 0;
        for (let item of arr) {
            n += item;
        }
        resolve(n);
    }

    let promise = new Promise(add);
    promise.then(function (data) {
        alert(data);
    })

    async function add2(a1,a2,a3,a4,a5) {
        let arr2=[a1,a2,a3,a4,a5];
        let n=0;
        for (let index of arr2){
            n+=index;
        }
       return n;
    }
    let readd2=add2(1,3,5,7,9);
    readd2.then(function (data) {
        alert(data);
    });
</script>
</body>
</html>